#ifndef __CTRL_H
#define __CTRL_H

#include "../rtos/mutex.h"
#include "../utils//nocopyable.h"


namespace driver {

#define CTRL_PARTS(XX)                                                         \
    XX(0, COOKING_ROOM_LED, 煮面室LED)                                         \
    XX(1, COOKING_ROOM_FAN, 煮面室风扇)                                        \
    XX(2, RADIATE_FAN, 散热风扇)                                               \
    XX(3, DRAIN_PUMP, 排水泵)                                                  \
    XX(4, V1, 电磁阀1)                                                         \
    XX(5, V2, 电磁阀2)                                                         \
    XX(6, V3, 电磁阀3)                                                         \
    XX(7, V4, 电磁阀4)                                                         \
    XX(8, V5, 电磁阀5)                                                         \
    XX(9, V6, 电磁阀6)                                                         \
    XX(10, V7, 电磁阀7)                                                        \
    XX(11, V8, 电磁阀8)                                                        \
    XX(12, HEAT_WATER, 开水加热器)                                             \
    XX(13, HEAT_STEAM, 蒸汽加热器)                                             \
    XX(14, WATER_PUMP, 抽水泵)

namespace parts {

enum impl {

#define XX(ID, NAME, DESCR) NAME = ID,
CTRL_PARTS(XX)
#undef  XX
    END,
};

}

class Ctrl : private utils::NoCopyable {

public:
    void init();

    void open(uint8_t id);
    void close(uint8_t id);

    uint16_t flags() const {
        return m_flags;
    }

    static const char *parts_name(uint8_t id) {
        switch (id) {
#define XX(ID, NAME, DESCR) case ID: return #DESCR;
            CTRL_PARTS(XX)
#undef  XX
        }
        return "未知";
    }

private:
    uint16_t m_flags = 0;
    rtos::Mutex m_mutex;
};

extern Ctrl ctrl;

} // namespace driver

#endif
